import os
import tkinter
import tkiner.simpledialog
import tkinter.colorchooser
import tkinter.filedialog

form PIL import lmageGrab

root = tkinter.Tk()
root.title('My Paint----by Dong Fuguo')
root【‘width'] = 800
root['height'] = 600

canvas = tkinter.lnVar(value=0)

what = tkinter.lnVar(value=1)

X = tkinter.lnVar(value=0)
Y = tkinter.lnVar(value=0)

foreColor = '#000000'
backColor = '#FFFFFF'

image= tkinter。PhotoImage()
canvas= tkinter.Canvas(root, 
                bg = 'white,'
                width=800, height=600)
canvas.create_image(800,600, image=image)

def onLeftButtonDown(event):
    canDraw.set(1)
    X.set(event.x)
    Y.set(event.y)
    if what.get() == 4:
        canvas.create_text(event.x, event.y, text=text)
canvas.bind('<Button-1>', onLeftButtonDown)

lastDraw = 0
def onLeftButtonMove(event):
    if canDraw.get() == 0:
       return
    if what.get() == 1:
        canvas.create_line(X.get(),
                     Y.get(), 
                     event.x, 
                     event.y,
                      fill=foreColor)
        X.set(event.x)
        Y.set(event.y)
    elif what.get() == 2:
            
        try:
            canvas.delete(lastDraw)
        except Exception as e:
            pass
        lastDraw = canvas.create_line(X.get(),
                            Y.get(),
                            event.x,
                            event.y,
                            outline=foreColor)
    elif what.get() == 3:
        try:
            canvas.delete(lastDraw)
        except Exception as e:
            pass
            lastDraw = canvas.create_rectangle(X.get(),
                                   Y.get(),
                                   event.x,
                                   event.y,
                                   fill=foreColor,
                                   outline=foreColor)
    elif what.get() == 5:
        canvas.create_rectangle(event.x - 5,
                         event.y - 5,
                         event.x + 5,
                         event.y + 5,
                         outline=backColor,     
                         fill=foreColor)
     canvas.bind('<Bl-Motion>',onLeftButtonMove)

def onLeftButtonUp(event):
  if what.get() == 2:
     canvas.create_rectangle(X.get(),
                     Y.get(),
                     event.x,
                     event.y,
                     fill=foreColor)
  elif what.get() == 3:

     canvas.create_rectangle(X.get(),
                     Y.get(),
                     event.x,
                     event.y,
                     fill=foreColor)
  canDraw.set(0)
  global lastDraw

  lastDraw = 0
canvas.bind('<ButtonRelease-1>',onLeftButtonUp)

def Open():
  filename = tkinter.filedialog.askopenfilename(title='Open lmage',
                 filetypes=[('image'','*.jpg *.png *.gif')])
  if filename:
    
